Skip to content

validate transformer#671

Merged
alexanderkirtzel merged 2 commits into
mainfrom
670-validate
Jun 9, 2026
Merged

validate transformer#671
alexanderkirtzel merged 2 commits into
mainfrom
670-validate

Conversation

@alexanderkirtzel

@alexanderkirtzel alexanderkirtzel commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

New @walkeros/transformer-validate transformer that validates events against JSON Schema contracts. Runs in both web and server flows, supports strict and pass modes, and writes the verdict and error list to configurable paths so you can gate or observe event quality.

The declarative per-step validate field on sources, transformers, and destinations is removed. Define event shapes in the top-level contract and enforce them at runtime by adding a transformer-validate step that references them via $contract.<name>. Design-time validation now checks step examples against the resolved contract.

Summary by CodeRabbit

  • New Features

    • Scoped generic HTML data attributes (data-elb_) for element-scoped properties
    • New validate transformer to enforce top-level contracts at runtime (strict/pass modes)
    • CLI validation supports a --strict option for treating contract violations as errors
  • Breaking Changes

    • Removed per-step validate configuration; validation is now performed via the validate transformer and top-level contract
  • Documentation

    • Docs updated with contract/validate usage, examples, and migration guidance

@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e5311a85-b4c8-4fc2-8bcd-4229fb3d7b78

📥 Commits

Reviewing files that changed from the base of the PR and between 23d4b86 and 0cad016.

📒 Files selected for processing (4)
  • .changeset/validate-schema-only-fix.md
  • packages/transformers/validate/src/__tests__/validate.test.ts
  • packages/transformers/validate/src/validate.ts
  • website/docs/transformers/validate.mdx
✅ Files skipped from review due to trivial changes (1)
  • .changeset/validate-schema-only-fix.md
🚧 Files skipped from review as they are similar to previous changes (3)
  • website/docs/transformers/validate.mdx
  • packages/transformers/validate/src/validate.ts
  • packages/transformers/validate/src/tests/validate.test.ts

📝 Walkthrough

Walkthrough

This PR removes step-level validate config, introduces the @walkeros/transformer-validate package and runtime validator, threads CLI strict-mode validation, implements tagger.scoped() emitting data-elb_, and updates tests, docs, and changesets accordingly.

Changes

Step-Level Validate Removal and Contract Architecture Shift

Layer / File(s) Summary
Core types and schema removal of validate field
packages/core/src/types/*.ts, packages/core/src/schemas/flow.ts, packages/core/src/schemas/index.ts
Removes optional validate field from Flow.Source/Destination/Transformer interfaces and Init types; deletes ValidateSchema and validateJsonSchema exports.
Flow resolution removes validate field
packages/core/src/flow.ts
Resolved flow objects for sources/transformers/destinations no longer carry validate.
Step entry validation retires validate key
packages/core/src/step-entry.ts
Replaces allowed top-level key validate with variables, causing validate to be treated as UNKNOWN_KEY.
Contract resolution and metadata extraction
packages/core/src/contract.ts, packages/core/src/schemas/intellisense.ts, packages/core/src/schemas/validate-flow-config.ts
Adds stripAnnotations option to resolveContracts, and refactors contract extraction to derive per-action property metadata (type/description/required) from resolved schemas.
Tests for retired validate and enhanced contracts
packages/core/src/__tests__/*
Adds tests verifying validate removal, contract annotation stripping, resolution edge cases, and extracted contract metadata.
CLI validation with strict mode and contract compliance
packages/cli/src/commands/validate/, packages/cli/src/__tests__/unit/validate/flow.test.ts
Adds strict option to validate API/CLI, uses validateEventAgainstContract for example-vs-contract checks, and emits warnings or CONTRACT_VIOLATION errors depending on strict mode.

New @walkeros/transformer-validate Package

Layer / File(s) Summary
Package configuration and build
packages/transformers/validate/package.json, tsconfig.json, tsup.config.ts, jest.config.mjs
Adds new package with build/test configuration and exports.
Type definitions for validator
packages/transformers/validate/src/types.ts
Defines ContractSource, ValidateOutput, ValidateSettings, ValidationIssue, ValidateResult types.
Core validation engine and transformer
packages/transformers/validate/src/validate.ts, src/transformer.ts, src/schemas/settings.ts
Implements validator cache/getValidator, schema collection (including generated event-format schema), validateEventAgainstContract, and transformerValidate runtime behavior (mode strict/pass, ingest writes, optional isValid writes).
Generated event format schema
packages/transformers/validate/src/event-format.schema.ts, scripts/generate-format-schema.mjs
Adds build-time generator and generated WalkerOS partial event schema constant used for format validation.
Step examples and implementation hints
packages/transformers/validate/src/examples/step.ts, src/hints.ts
Provides examples demonstrating strict/pass behaviors and hints for configuration.
Validation logic and transformer tests
packages/transformers/validate/src/__tests__/*
Adds extensive tests for schema selection, wildcard precedence, format checks, transformer modes, output routing, bundle isolation, and schema sync.
Public exports and dev entry point
packages/transformers/validate/src/index.ts, src/dev.ts, src/schemas/index.ts, src/examples/index.ts
Barrel exports and dev namespace exposing runtime and dev utilities.

Scoped Generic Data Attribute Feature

Layer / File(s) Summary
Web tagger scoped method implementation
packages/web/sources/browser/src/tagger.ts
Adds scoped() overloads (key/value or object), stores scoped properties, and emits data-elb_ attribute with serialized scoped values.
Tagger and walker scoped tests
packages/web/sources/browser/src/__tests__/tagger.test.ts, __tests__/walker.test.ts
Adds tests for scoped single/object inputs, accumulation, escaping, custom prefix, and integration with walker event extraction.
MCP generate tool scoped support
packages/mcps/source-browser/src/tools/generate.ts, src/__tests__/tools/generate.test.ts
Adds optional scoped input to generate_tagging tool and forwards scoped properties to tagger generation.
CLI example config update
packages/cli/examples/flow-complete.json
Removes step-level validate example from flow-complete.json.

Documentation and Package Dependencies

Layer / File(s) Summary
Flow and transformer skill documentation
skills/walkeros-understanding-flow/SKILL.md, skills/walkeros-understanding-transformers/SKILL.md
Docs updated: event shapes live in top-level contract; runtime enforcement via transformer-validate; available transformers listed.
Flow documentation updates
website/docs/getting-started/flow/contract.mdx, website/docs/getting-started/flow/validate.mdx
Rewrites to show transformer-based enforcement and validate transformer settings (contract, format, mode, output).
Web source tagger documentation
website/docs/sources/web/browser/tagger.mdx
Adds scoped() usage examples and API reference documenting data-elb_.
New transformer-validate documentation
website/docs/transformers/validate.mdx, website/sidebars.ts
Documentation page added and sidebar updated.
CLI package dependency
packages/cli/package.json
Adds @walkeros/transformer-validate@4.1.2 as a dependency and updates examples accordingly.

Sequence Diagram(s)

sequenceDiagram
  participant CLI
  participant validateFlow
  participant resolveContracts
  participant TransformerValidate
  participant cfworkerValidator
  participant Ingest

  CLI->>validateFlow: validate(flow, { strict? })
  validateFlow->>resolveContracts: resolveContracts(flow.contract)
  validateFlow->>TransformerValidate: validateEventAgainstContract(event, { contracts, format })
  TransformerValidate->>cfworkerValidator: getValidator(schema) / validate(event)
  cfworkerValidator-->>TransformerValidate: validation errors[]
  TransformerValidate->>Ingest: write errors to ingest at errorsPath
  TransformerValidate-->>validateFlow: isValid / errors
  validateFlow-->>CLI: report warnings/errors (CONTRACT_VIOLATION if strict)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Poem

🐰 A rabbit tucked in code so neat,

scoped keys nest where triggers meet,
Contracts moved to highest shelf,
A transformer guards event health;
data-elb_ now marks the beat.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 670-validate

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/cli/src/__tests__/unit/validate/flow.test.ts`:
- Line 762: The test fixture uses underscore-style event naming in the 'out'
array (out: ['event', 'page_view']) but the repo requires space-delimited
"entity action" names; update the fixture value from 'page_view' to 'page view'
so the 'out' array becomes ['event', 'page view'] and ensure any assertions or
snapshots referring to that value are updated accordingly.

In `@packages/transformers/validate/src/validate.ts`:
- Around line 31-37: The type-guard isContractRule currently only recognizes a
ContractRule if it has an events object, so Flow.ContractRule values that only
provide a schema are misclassified and cause collectSchemas to push the whole
rule; update isContractRule to accept a rule if it has a valid schema (e.g.,
'schema' in source) or if 'events' exists and is an object, ensuring the
predicate returns true for schema-only rules, and mirror the same change where
the same pattern appears (the similar block around lines 66-76) so
collectSchemas will extract source.schema instead of the entire rule object.
- Around line 25-27: The validator is hardcoded to '2020-12' in getValidator
(cfworker.Validator(mutable, '2020-12')) while event-format.schema.ts declares
draft-07; change getValidator to detect the schema draft from mutable.$schema
when present (map 'http://json-schema.org/draft-07/schema#' to the draft-07
identifier used by cfworker) and pass that draft to cfworker.Validator, falling
back to '2020-12' only if no $schema is present; update the validatorCache usage
accordingly and/or alternatively regenerate eventFormatSchema to use 2020-12
tuple syntax (prefixItems) if you prefer pinning to 2020-12.

In `@website/docs/transformers/validate.mdx`:
- Around line 65-66: Update the paragraph describing the transformer to clarify
that the transformer reads the { ingest, event } context and that each contract
entry enforces required fields while format: true only performs structural/type
validation against the canonical WalkerOS.Event shape (not enforcement of
contract-required fields); revise the sentence that currently implies full
WalkerOS.Event enforcement to explicitly state that required-field checks come
from contract entries (e.g., $contract.<name>) and format: true only validates
shape/types of the canonical partial event and aggregates errors accordingly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f7003bad-02ee-4576-927f-40b17d558e83

📥 Commits

Reviewing files that changed from the base of the PR and between 7662b37 and 23d4b86.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (61)
  • .changeset/scoped-generic-data-attribute.md
  • .changeset/transformer-validate.md
  • packages/cli/examples/flow-complete.json
  • packages/cli/package.json
  • packages/cli/src/__tests__/unit/validate/flow.test.ts
  • packages/cli/src/commands/validate/index.ts
  • packages/cli/src/commands/validate/validators/flow.ts
  • packages/core/src/__tests__/contract.test.ts
  • packages/core/src/__tests__/flow.test.ts
  • packages/core/src/__tests__/schemas/flow-validate-retired.test.ts
  • packages/core/src/__tests__/schemas/validate-flow-config.test.ts
  • packages/core/src/__tests__/step-entry.test.ts
  • packages/core/src/contract.ts
  • packages/core/src/flow.ts
  • packages/core/src/schemas/__tests__/validate-json-schema.test.ts
  • packages/core/src/schemas/flow.ts
  • packages/core/src/schemas/index.ts
  • packages/core/src/schemas/intellisense.ts
  • packages/core/src/schemas/validate-flow-config.ts
  • packages/core/src/step-entry.ts
  • packages/core/src/types/destination.ts
  • packages/core/src/types/flow.ts
  • packages/core/src/types/index.ts
  • packages/core/src/types/source.ts
  • packages/core/src/types/transformer.ts
  • packages/core/src/types/validate.ts
  • packages/mcps/source-browser/src/__tests__/tools/generate.test.ts
  • packages/mcps/source-browser/src/tools/generate.ts
  • packages/transformers/validate/jest.config.mjs
  • packages/transformers/validate/package.json
  • packages/transformers/validate/scripts/generate-format-schema.mjs
  • packages/transformers/validate/src/__tests__/bundle-isolation.test.ts
  • packages/transformers/validate/src/__tests__/format-schema-sync.test.ts
  • packages/transformers/validate/src/__tests__/scaffold.test.ts
  • packages/transformers/validate/src/__tests__/settings.schema.test.ts
  • packages/transformers/validate/src/__tests__/stepExamples.test.ts
  • packages/transformers/validate/src/__tests__/transformer.test.ts
  • packages/transformers/validate/src/__tests__/validate.test.ts
  • packages/transformers/validate/src/dev.ts
  • packages/transformers/validate/src/event-format.schema.ts
  • packages/transformers/validate/src/examples/index.ts
  • packages/transformers/validate/src/examples/step.ts
  • packages/transformers/validate/src/hints.ts
  • packages/transformers/validate/src/index.ts
  • packages/transformers/validate/src/schemas/index.ts
  • packages/transformers/validate/src/schemas/settings.ts
  • packages/transformers/validate/src/transformer.ts
  • packages/transformers/validate/src/types.ts
  • packages/transformers/validate/src/validate.ts
  • packages/transformers/validate/tsconfig.json
  • packages/transformers/validate/tsup.config.ts
  • packages/web/sources/browser/src/__tests__/tagger.test.ts
  • packages/web/sources/browser/src/__tests__/walker.test.ts
  • packages/web/sources/browser/src/tagger.ts
  • skills/walkeros-understanding-flow/SKILL.md
  • skills/walkeros-understanding-transformers/SKILL.md
  • website/docs/getting-started/flow/contract.mdx
  • website/docs/getting-started/flow/validate.mdx
  • website/docs/sources/web/browser/tagger.mdx
  • website/docs/transformers/validate.mdx
  • website/sidebars.ts
💤 Files with no reviewable changes (9)
  • packages/core/src/step-entry.ts
  • packages/core/src/types/destination.ts
  • packages/core/src/types/source.ts
  • packages/core/src/types/validate.ts
  • packages/cli/examples/flow-complete.json
  • packages/core/src/types/transformer.ts
  • packages/core/src/schemas/index.ts
  • packages/core/src/schemas/flow.ts
  • packages/core/src/flow.ts

action: 'view',
data: { title: 'Home' },
},
out: ['event', 'page_view'],

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Use space-delimited event naming in the fixture.

Line 762 uses 'page_view', but this repo requires 'entity action' format with spaces.

Suggested fix
-                  out: ['event', 'page_view'],
+                  out: ['event', 'page view'],

As per coding guidelines, **/*.{ts,tsx,js,jsx}: Use event naming format: 'entity action' with space (e.g., 'page view', not 'page_view').

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
out: ['event', 'page_view'],
out: ['event', 'page view'],
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/cli/src/__tests__/unit/validate/flow.test.ts` at line 762, The test
fixture uses underscore-style event naming in the 'out' array (out: ['event',
'page_view']) but the repo requires space-delimited "entity action" names;
update the fixture value from 'page_view' to 'page view' so the 'out' array
becomes ['event', 'page view'] and ensure any assertions or snapshots referring
to that value are updated accordingly.

Source: Coding guidelines

Comment on lines +25 to +27
// Pin draft 2020-12 (the contract authoring draft).
const validator = new cfworker.Validator(mutable, '2020-12');
validatorCache.set(key, validator);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify draft mismatch in current tree (read-only)
rg -n --fixed-strings "new cfworker.Validator" packages/transformers/validate/src/validate.ts
rg -n --fixed-strings "\$schema: 'http://json-schema.org/draft-07/schema#'" packages/transformers/validate/src/event-format.schema.ts
rg -n --fixed-strings "items: [" packages/transformers/validate/src/event-format.schema.ts

Repository: elbwalker/walkerOS

Length of output: 231


Fix JSON Schema draft mismatch in validate transformer (draft-07 schema validated as 2020-12).
getValidator hard-pins new cfworker.Validator(mutable, '2020-12'), while event-format.schema.ts declares $schema: 'http://json-schema.org/draft-07/schema#' and uses draft-07 tuple-style items: [...] (e.g., ordered tuple arrays). This can change positional tuple validation semantics (including the format: true validation path). Derive the validator draft from schema.$schema when present, or update/regenerate eventFormatSchema to 2020-12 tuple form (prefixItems).

// Pin draft 2020-12 (the contract authoring draft).
const validator = new cfworker.Validator(mutable, '2020-12');
validatorCache.set(key, validator);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/transformers/validate/src/validate.ts` around lines 25 - 27, The
validator is hardcoded to '2020-12' in getValidator (cfworker.Validator(mutable,
'2020-12')) while event-format.schema.ts declares draft-07; change getValidator
to detect the schema draft from mutable.$schema when present (map
'http://json-schema.org/draft-07/schema#' to the draft-07 identifier used by
cfworker) and pass that draft to cfworker.Validator, falling back to '2020-12'
only if no $schema is present; update the validatorCache usage accordingly
and/or alternatively regenerate eventFormatSchema to use 2020-12 tuple syntax
(prefixItems) if you prefer pinning to 2020-12.

Comment thread packages/transformers/validate/src/validate.ts Outdated
Comment thread website/docs/transformers/validate.mdx Outdated
@alexanderkirtzel alexanderkirtzel merged commit 0a223fa into main Jun 9, 2026
4 of 5 checks passed
@alexanderkirtzel alexanderkirtzel deleted the 670-validate branch June 9, 2026 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant